using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JGSY.CMS.LowCode.Platform.Domain.Entities;
using JGSY.CMS.LowCode.Platform.Domain.Enums;

namespace JGSY.CMS.LowCode.Platform.Domain.Interfaces
{
    /// <summary>
    /// 工作流实例仓储接口
    /// </summary>
    public interface IWorkflowInstanceRepository : IRepository<WorkflowInstance>
    {
        /// <summary>
        /// 根据工作流ID获取实例列表
        /// </summary>
        /// <param name="workflowId">工作流ID</param>
        /// <returns>实例列表</returns>
        Task<List<WorkflowInstance>> GetByWorkflowIdAsync(long workflowId);

        /// <summary>
        /// 根据发起人获取实例列表
        /// </summary>
        /// <param name="initiatedBy">发起人ID</param>
        /// <returns>实例列表</returns>
        Task<List<WorkflowInstance>> GetByInitiatorAsync(long initiatedBy);

        /// <summary>
        /// 根据状态获取实例列表
        /// </summary>
        /// <param name="status">状态</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <returns>实例列表</returns>
        Task<IEnumerable<WorkflowInstance>> GetByStatusAsync(WorkflowInstanceStatus status, int pageIndex = 1, int pageSize = 20);

        /// <summary>
        /// 获取运行中的实例列表
        /// </summary>
        /// <returns>运行中实例列表</returns>
        Task<List<WorkflowInstance>> GetRunningInstancesAsync();

        /// <summary>
        /// 获取超时的实例列表
        /// </summary>
        /// <returns>超时实例列表</returns>
        Task<List<WorkflowInstance>> GetTimeoutInstancesAsync();

        /// <summary>
        /// 获取实例执行统计
        /// </summary>
        /// <param name="workflowId">工作流ID</param>
        /// <returns>统计信息</returns>
        Task<Dictionary<string, int>> GetExecutionStatisticsAsync(long workflowId);

        /// <summary>
        /// 批量更新实例状态
        /// </summary>
        /// <param name="ids">实例ID列表</param>
        /// <param name="status">新状态</param>
        /// <returns>是否成功</returns>
        Task<bool> BatchUpdateStatusAsync(List<long> ids, string status);

        /// <summary>
        /// 清理已完成的实例
        /// </summary>
        /// <param name="beforeDate">清理日期之前的</param>
        /// <returns>清理的数量</returns>
        Task<int> CleanupCompletedInstancesAsync(DateTime beforeDate);
    }
}
